package com.wxboot.game.eliminate.init;

import com.wxboot.game.eliminate.base.JellyCell;
import com.wxboot.game.eliminate.modules.service.JellyEliminateInitService;
import com.wxboot.game.eliminate.support.JellyBeanGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.Objects;

import static com.wxboot.game.eliminate.config.JellyConstant.CELL_NUM;
import static com.wxboot.game.eliminate.config.JellyConstant.LEVEL_NUM;

@Component
public class GameLevelInit {

    private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    @Value("${eliminate-jelly.matrix.init}")
    private Boolean isInit;

    @Autowired
    private JellyEliminateInitService jellyEliminateInitService;

    @PostConstruct
    public void GameLevelInit() {
        if (Objects.equals(isInit, Boolean.TRUE)) {
            // 初始化游戏关卡矩阵
            List<JellyCell[][]> jellyMatrix = JellyBeanGenerator.initJellyMatrixList(LEVEL_NUM, CELL_NUM);
            jellyEliminateInitService.initJellyMatrixLevel(jellyMatrix);
            LOGGER.info("jelly game matrix levels initialized");
        }
    }


}
